#ifndef TRAJECTORY_H
#define TRAJECTORY_H

#include "basicheader.h"
#include "DataVector.h"

#define _TRAJECTORY_BEGIN_ namespace trajectory{
#define _TRAJECTORY_END_ };

_TRAJECTORY_BEGIN_

typedef std::pair<double, double> Point;
typedef std::pair<Point, Point> Line;

typedef struct
{
	std::vector<std::pair<int, Line>*> closeLine;	//The Line and its belonging traj ID
	//std::vector<std::pair<int, int>> closeLine;
} CL;

typedef struct
{
	std::vector<int> closeTraj;	//The id of the trajectories that close to the fine-partition
} CTR;

class Trajectory
{
public:
	Trajectory();
	Trajectory(const Trajectory& obj);
	Trajectory& operator=(const Trajectory& obj);

	~Trajectory();

public:
	inline DataPoint& operator[](int index) { return m_Points[index]; }
	inline const DataPoint& operator[](int index) const { return m_Points[index]; }
	inline int size() const { return m_Points.size(); }
	inline void resize(int size) { m_Points.resize(size); }
	inline const std::string& getName() const { return m_Name; }
	inline void setName(const std::string& name) { m_Name = name; }
	inline void addPoint(const DataPoint& point) { m_Points.push_back(point); }
	const std::vector<int>& coarsePartition();

	/************************************************************************/
	/*	Calculate the coarse parameters maxper, maxlen, minlen, maxthe.     */
	/************************************************************************/
	void calculateCoarseParameters();
	/************************************************************************/
	/*	Get the coarse parameters(maxper, maxlen, minlen, maxthe) by index. */
	/************************************************************************/
	void getCoarseParameters(int index, double& maxPer, double& maxLen, double& minLen, double& maxThe);
	inline const std::vector<int>& getCoarsePartition() { return m_CP; }
	//inline std::vector<CL>& getCL() { return m_CL; }
	//inline std::vector<CTR>& getCTR() { return m_CTR; }

protected:

	double calculateMDLnopar(int i, int j);
	double calculateMDLpar(int i, int j);

private:
	std::string m_Name;
	std::vector<DataPoint> m_Points;
	std::vector<int> m_CP;

	std::vector<double> m_MaxPer;
	std::vector<double> m_MaxLen;
	std::vector<double> m_MinLen;
	std::vector<double> m_MaxThe;

	//std::vector<CL> m_CL;	
	//std::vector<CTR> m_CTR;	//	each element is a CTR set of li of fine partition, the element is the ID of the close traj
};



_TRAJECTORY_END_

#endif

